In [3]:
#Project Euler 8
thoudigits = 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
def adj13(digit):
tempprod = 1
maxprod = 0
for i in range(0,len(str(digit))-13):
for j in range(0,13):
tempprod = tempprod*int(str(digit)[i+j])
if(tempprod>maxprod):
maxprod = tempprod
tempprod = 1
print(maxprod)
adj13(thoudigits)
In [6]:
#NumPy Noise
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
p = np.array([1,2,3,5,1,2,3,1,2,2,6,3,1,1,5,1,1,3,2,1])
l = 100*np.array([-0.06878584, -0.13865453, -1.61421586, 1.02892411, 0.31529163, -0.06186747, -0.15273951, 1.67466332, -1.88215846, 0.67427142, 1.2747444, -0.0391945, -0.81211282, -0.38412292, -1.01116052, 0.25611357, 0.3126883, 0.8011353, 0.64691918, 0.34564225])
noise = np.random.normal(0, .12, len(l))
iq1 = (p+l)/((p*l)**3)
noisyp = p+p*noise
noisyl = l+l*noise
iq2 = (noisyp+noisyl)/(noisyp*noisyl)**2
print(np.mean(iq2-iq1))
plt.figure(figsize=(15,20))
plt.subplot(511)
plt.plot(p,l,"r.")
plt.subplot(512)
plt.plot(noisyp,noisyl,"b.")
plt.subplot(513)
plt.plot(iq1,"g.")
plt.subplot(514)
plt.plot(iq2,"y.")
plt.subplot(515)
plt.plot(iq1-iq2,"k.")
Out[6]:
In [7]:
#Seive
import numpy as np
def seive(maxim):
A=np.ones(maxim, dtype=bool)
for i in range(2,int(np.ceil(np.sqrt(maxim)))):
if A[i]==True:
for j in [i**2+n*i for n in range(0,maxim) if i**2+n*i<maxim]:
A[j]=False
print(np.linspace(0,maxim, maxim+1)[A])
seive(100)
In [ ]:
#Linear Widget
def linear(m,b):
error = sum((y-(m*x+b))**2)
print(error)
plt.plot(x,y,'ro')
plt.plot(x,m*x+b)
widg.interact(linear, m=(-10,10,.1), b=(-5,5,.1))